package com.example.yeujian5.yuejian5.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yeujian5.yuejian5.Listenner.MatchDetailListener;
import com.example.yeujian5.yuejian5.R;
import com.example.yeujian5.yuejian5.bean.MatchBean;
import com.example.yeujian5.yuejian5.model.MatchModel;
import com.squareup.picasso.Picasso;

public class MatchDetailActivity extends AppCompatActivity implements MatchDetailListener,View.OnClickListener{


    private ImageView img;
    private TextView name,intro,time,num,place;
    private Button baoming;
    Intent intent;
    public  String Picid;
    public int id;
    public MatchBean list;
    ImageView reg_return;
    String adress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_match_detail);
        intent=getIntent();
        Picid=intent.getStringExtra("id");
        MatchModel matchModel=new MatchModel();
        matchModel.getMatchById(Picid,this);
        initViews();
        //baoming.setOnClickListener(this);
        reg_return.setOnClickListener(this);
        place.setOnClickListener(this);
    }

    public void initViews() {
        img= (ImageView) findViewById(R.id.img);
        intro= (TextView) findViewById(R.id.intro);
        name= (TextView) findViewById(R.id.name);
        time= (TextView) findViewById(R.id.time);
        num= (TextView) findViewById(R.id.hits);
        place=(TextView)findViewById(R.id.place) ;
        baoming= (Button) findViewById(R.id.baoming);
        reg_return= (ImageView) findViewById(R.id.reg_return);

    }

    @Override
    public void onResponse(MatchBean bean) {

        list=bean;
        adress=list.getUrl();
        intro.setText(list.getIntroduction());
        place.setText(adress);

        name.setText(list.getName());
        time.setText(list.getCdate());
        num.setText(list.getHits());
        if(!list.getThumb().isEmpty())
        {
            Picasso.with(this).load("http://172.24.10.175/workout/Uploads/"+list.getThumb()).into(img);
        }
        else
        {
            img.setImageResource(R.drawable.ic_me);
        }
    }

    @Override
    public void onFail(String msg) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){

            case R.id.reg_return:
                finish();

            case R.id.place:
                 Intent inten = new Intent();
                 inten.setData(Uri.parse(adress));
                 inten.setAction(Intent.ACTION_VIEW);
                 startActivity(inten);

        }
    }
}
